<template>
  <div class="home-module__topic container">
    <div class="topic-header">
      <div class="title">{{ datas.title }}</div>
      <div class="more" @click="goMore">更多</div>
    </div>

    <!-- 宫格 -->
    <div v-if="datas.arrange == 1" class="topic-list gongge" :class="`col-${datas.column}`">
      <div v-for="(item, index) in datas.list" :key="index" class="item">
        <div class="picture" @click="goTopic(item.id)">
          <edu-image class="hvr-float" :src="item.cover_url" fit="cover" lazy></edu-image>
        </div>
        <div class="content">
          <div class="title" @click="goTopic(item.id)">{{ item.title }}</div>
          <div class="firmware">{{ item.abstract }}</div>
          <div class="parallel">
            <div class="time">{{ item.publish_time | parseTime('{y}-{m}-{d}') }}</div>
            <div class="price"><i class="el-icon-view el-icon--left"></i>{{ item.read_count }}</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 滚动 -->
    <div
      v-else-if="datas.arrange == 2"
      class="topic-list scroll"
      :class="`topic-list-swiper-${moduleIndex}`"
    >
      <swiper :options="topicSwiperOption">
        <swiper-slide v-for="(item, index) in datas.list" :key="index">
          <div class="item">
            <div class="picture" @click="goTopic(item.id)">
              <edu-image class="hvr-sink" :src="item.cover_url" fit="cover" lazy></edu-image>
            </div>
            <div class="content">
              <div class="title" @click="goTopic(item.id)">{{ item.title }}</div>
              <div class="firmware">{{ item.abstract }}</div>
              <div class="parallel">
                <div class="time">{{ item.publish_time | parseTime('{y}-{m}-{d}') }}</div>
                <div class="price">
                  <i class="el-icon-view el-icon--left"></i>{{ item.read_count }}
                </div>
              </div>
            </div>
          </div>
        </swiper-slide>
      </swiper>
      <div class="swiper-button-prev swiper-button-white"></div>
      <div class="swiper-button-next swiper-button-white"></div>
    </div>
  </div>
</template>

<script>
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'
export default {
  name: 'Topic',
  components: {
    Swiper,
    SwiperSlide
  },
  props: {
    datas: {
      type: Object,
      default: () => {}
    },
    moduleIndex: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      topicSwiperOption: {
        slidesPerView: 3,
        spaceBetween: 20,
        loop: false,
        loopAdditionalSlides: 0,
        navigation: {
          nextEl: `.topic-list-swiper-${this.moduleIndex} .swiper-button-next`,
          prevEl: `.topic-list-swiper-${this.moduleIndex} .swiper-button-prev`
        }
      }
    }
  },
  methods: {
    // 跳转更多
    goMore() {
      this.$router.push({
        path: '/topic'
      })
    },
    // 跳转讲师
    goTopic(id) {
      if (id == 0) return
      this.$router.push({
        path: '/topic/details',
        query: {
          id: id
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '@/styles/hover.scss';
.home-module__topic {
  margin-bottom: 30px;
  padding: 30px 0;
  background-color: #ffffff;
  .topic-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    border-left-width: 3px;
    border-left-style: solid;
    @include edu-color-primary(border-left-color);
    .title {
      font-size: 18px;
      font-weight: bold;
      color: #333333;
      line-height: 22px;
    }
    .more {
      font-size: 14px;
      font-weight: 400;
      color: #aeaeae;
      line-height: 16px;
      cursor: pointer;
    }
  }
  .topic-list {
    padding: 0 15px;
    margin-top: 30px;
    .item {
      .picture {
        cursor: pointer;
        .el-image {
          width: 100%;
          height: 100%;
        }
      }
      .content {
        .title {
          font-size: 18px;
          font-weight: 500;
          color: $text-color-import;
          cursor: pointer;
          @include ellipsis;
        }
        .firmware {
          height: 44px;
          font-size: 14px;
          font-weight: 400;
          color: $text-color-secondary;
          line-height: 22px;
          @include ellipsisLine(2);
        }
        .parallel {
          display: flex;
          align-items: center;
          justify-content: space-between;
          font-size: 14px;
          font-weight: 400;
          color: #b7bac1;
        }
      }
    }
    &.gongge {
      display: grid;
      .item {
        grid-column: span 1 / span 1;
      }
      &.col-2 {
        grid-gap: 28px 24px;
        grid-template-columns: repeat(2, minmax(0px, 1fr));
        .item {
          padding: 10px;
          display: flex;
          background: rgba(48, 49, 51, 0.02);
          border-radius: 6px;
          .picture {
            width: 243px;
            height: 132px;
          }
          .content {
            flex: 1;
            min-width: 0;
            padding-top: 8px;
            display: flex;
            flex-direction: column;
            margin-left: 10px;
            .parallel {
              margin-top: auto;
            }
            .firmware {
              margin-top: 10px;
            }
            .deduction {
              margin-top: 18px;
            }
          }
        }
      }
      &.col-3,
      &.col-4 {
        grid-gap: 28px 20px;
        .item {
          .content {
            margin-top: 15px;
            .firmware {
              margin-top: 10px;
            }
            .parallel {
              margin-top: 15px;
            }
          }
        }
      }
      &.col-3 {
        grid-template-columns: repeat(3, minmax(0px, 1fr));
        .item {
          .picture {
            height: 207px;
          }
        }
      }
      &.col-4 {
        grid-template-columns: repeat(4, minmax(0px, 1fr));
        .item {
          .picture {
            height: 153px;
          }
        }
      }
    }
    &.scroll {
      position: relative;
      padding: 0 40px;
      .swiper-button-prev,
      .swiper-button-next {
        outline: none;
        width: 20px;
        height: 20px;
        top: 99px;
        margin-top: -10px;
        color: #b7bac1;
        &:after {
          font-size: 16px;
        }
        &:hover {
          @include edu-color-primary;
        }
      }
      .swiper-button-prev.swiper-button-disabled,
      .swiper-button-next.swiper-button-disabled {
        pointer-events: auto;
        &:hover {
          color: #b7bac1 !important;
        }
      }
      .swiper-button-prev {
        left: 15px;
      }
      .swiper-button-next {
        right: 15px;
      }
      .item {
        .picture {
          height: 198px;
        }
        .content {
          margin-top: 15px;
          .firmware {
            margin-top: 10px;
          }
          .parallel {
            margin-top: 20px;
          }
        }
      }
    }
  }
}
</style>
